package com.jackchan.homework.sysw.service;

import com.google.common.collect.Lists;
import com.jackchan.homework.common.utils.DateUtils;
import com.jackchan.homework.sysw.dto.OrderDto;
import com.jackchan.homework.sysw.entity.Order;
import com.jackchan.homework.sysw.repository.OrderDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;

/**
 * Created by ch-hui on 16/2/10.
 */

@Service
public class OrderService {

    @Autowired
    private OrderDao orderDao;

    public List<OrderDto> findAllOrderDtoes(){
        List<OrderDto> dtoes = Lists.newArrayList();
        for(Iterator<Order> iter = orderDao.findAll().iterator();iter.hasNext();){
            Order order = iter.next();
            OrderDto dto = new OrderDto();
            dto.setId(order.getId());
            dto.setName(order.getRecipe().getRecipeName() + "订单" + order.getOrderTime().getTime());
            dto.setOrderTime(DateUtils.formatDateTime(order.getOrderTime()));
            dto.setTotalAmount(order.getTotalAmount());
            dto.setTotalCost(order.getTotalCost());
            dtoes.add(dto);
        }
        return dtoes;
    }





}
